#include <stdio.h>

int fib[50], fi[50], pre[50][50], fiplus[50][50], plus[50], n;

void dfs(int pos, int step) {
    if(pos > n) {
        printf("%lld\n", plus[step]);
        return ;
    }
    if(step == 0) {
        dfs(pos+1, step+1);
        return ;
    }
    for(int i = step ; i > 0 ; i -- ) {
        if( fi[pos][i] + pre[pos][step-i] <= plus[step-1])
            plus[step] = fi[pos][i] + pre[pos][step-i], dfs(pos+1, step+1);
        if( fi[pos][i] + plus[pos][step-i+1] <= plus[step-1])
            plus[step] = fi[pos][i] + plus[pos][step-i+1], dfs(pos+1, step+1);
    }
}

int main() {
    scanf("%d", &n);
    fib[1] = fib[2] = 1;
    for(int i = 2 ; i <= n ; i ++ )
        fib[i] = fib[i-1] + fib[i-2];
    for(int j = 1 ; j <= n ; j ++ )
        for(int i = 1 ; i <= n-j ; i ++ )
            fi[j][i] = fib[i+j-1];
    for(int i = 1 ; i <= n ; i ++ )
        for(int j = 0 ; j < 50 ; j ++ )
            pre[i][j] = pre[i-1][j] + fi[i][j];
    int T;
    scanf("%d", &T);
    while(T -- ) {
        ll x, tmp = 0;
        scanf("%lld", &x);
        for(int i = 0 ; x ; i ++ ) {
            while(tmp < x && fi[n][i])
                tmp += fi[n][i--], dfs(0, 0);
            x -= tmp;
        }
    }
    return 0;
}
